package d5_map_traversal_method;

import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;

public class MapDemo03 {
    public static void main(String[] args) {
        //目标: 掌握Map集合便利方式之三:
        Map<String, Integer> map = new HashMap<>();//一行经典代码
        map.put("陈平安", 178);
        map.put("姬紫月", 170);
        map.put("宁姚", 175);
        map.put("叶凡", 178);
        map.put("秦牧", 175);
        System.out.println(map);
        //{陈平安=178, 叶凡=178, 宁姚=175, 姬紫月=170, 秦牧=175}

        //本质还是键键值对转换成Entry对象,然后再进行获取键和值
        map.forEach(new BiConsumer<String, Integer>() {
            @Override
            public void accept(String key, Integer value) {
                System.out.println(key + "===" + value);
            }
        });
        map.forEach((key, value) -> {System.out.println(key + "===" + value);});


    }
}
